package ua.kpi.apolonov.questions;

import java.util.List;
import ua.kpi.apolonov.answers.Answer;
import ua.kpi.apolonov.parsers.Parsers;

/**
 * @version 4.0 12.03.2013
 * @author Yegor Apolonov
 */

public class RangeAnswerQuestion extends Question{

	private final int TRUE_ANSWER_NUMBER = 0;
	private Parsers parser = new Parsers();
	private int trueNumericAnswer = Integer.parseInt((getAnswer(TRUE_ANSWER_NUMBER).getAnswerText()));
	
	public RangeAnswerQuestion(String question, List<Answer> answers) {
		super(question, answers);
		setInquiry("\nВведите правильный ответ(ы)\n>> ");
	}
	
	public float inspectAnswers(String userAnswers) {
        float result = 0;
        int[] userNumbers = parser.toIntArrayUserAnswer(userAnswers);
        if(userNumbers.length == 1) {
        	 int answerNumber = userNumbers[0];
        	 int offsetTrueNumber = Math.abs(trueNumericAnswer - answerNumber);
             if(offsetTrueNumber < 3 ) {
                result = (3 - offsetTrueNumber)/3;
             }
        } else { result = 0;}
        return result;
    }

}
